<template>
  <view></view>
</template>

<script>
import { Toast, MessageBox } from "mint-ui";
import html5plus from "../../utils/html5plus.js";
import { getLiveInfo } from "../../api.js";
import { getGuid } from "@/utils/index";
export default {
  name: "live_screencap",
  data() {
    return {
      pusher: null,
      webview: null
    };
  },
  mounted() {
    var userInfo2 = JSON.parse(localStorage.userInfo || "false");
    if (!localStorage.zyUserId || !userInfo2) {
      MessageBox.confirm("去登录?").then(action => {
        this.$router.push("/login");
      });
      return;
    }
    // 监听plusready事件
    html5plus.plusready(
      () => {
        //获取直播数据
        getLiveInfo({
          accid: userInfo2.yx_user.yx_accid,
          machine_id: getGuid(),
          token: userInfo2.token,
          version: "H3.0.0"
        }).then(res => {
          if (res.data.code == 4040026) {
            //没有直播
            this.$router.push("/live/edit");
          } else if (res.data.code != 200) {
            Toast({
              message: res.data.msg,
              duration: 2000
            });
          } else {
            this.pusher = plus.video.createLivePusher("livepusher", {
              url: res.data.data[0].pushurl,
              //top: '0px',
              //left: '0px',
              //right: '0px',
              //bottom: '0px',
              position: "absolute"
            });
            plus.webview.currentWebview().append(this.pusher);
            this.webview = plus.webview.create(
              location.href.replace(/#.+/gi, "#/live/operate"),
              "live-operate",
              {
                background: "transparent",
                left: "0px",
                bottom: "0px",
                // right:'0px',
                // bottom:'0px',
                width: document.documentElement.clientWidth + "px",
                height: document.documentElement.clientHeight + "px",
                //      opacity: 0,
                //      progress: null,
                zindex: 1000
              }
            );
            this.webview.show();
          }
        });
      },
      () => {
        MessageBox.alert("请下载APP进行直播！");
        this.$router.push("/");
      }
    );
  },
  destroyed() {
    this.pusher && this.pusher.close();
    this.webview && this.webview.close();
  }
};
</script>

<style>
</style>
